import inquirer from 'inquirer';
import { blue, green, yellow } from 'kolorist';

export const getProjectName = async () => {
  const { projectName } = await inquirer.prompt([
    {
      name: 'projectName',
      type: 'input',
      message: 'Project name:',
      default: 'vue-project',
      validate: (input) => {
        if (!/^[a-z0-9-]+$/.test(input)) {
          return 'Project name must be lowercase with hyphens only';
        }
        return true;
      }
    }
  ]);
  return projectName;
};

export const getFeaturePrompts = () => [
  {
    name: 'typescript',
    type: 'confirm',
    message: 'Add TypeScript?',
    default: false
  },
  {
    name: 'jsx',
    type: 'confirm',
    message: 'Add JSX Support?',
    default: false
  },
  {
    name: 'router',
    type: 'confirm',
    message: 'Add Vue Router?',
    default: false
  },
  {
    name: 'pinia',
    type: 'confirm',
    message: 'Add Pinia for state management?',
    default: false
  },
  {
    name: 'vitest',
    type: 'confirm',
    message: 'Add Vitest for unit testing?',
    default: false
  },
  {
    name: 'eslint',
    type: 'confirm',
    message: 'Add ESLint for code quality?',
    default: false
  }
];

export const getOverwritePrompt = () => ({
  name: 'shouldOverwrite',
  type: 'confirm',
  message: (targetDir) => 
    `${targetDir} is not empty. Remove existing files and continue?`,
  default: false
});

export const displayFeatureSummary = (features) => {
  console.log();
  console.log(blue('Features to be installed:'));
  console.log();
  
  const featureStatus = Object.entries(features).map(([feature, enabled]) => {
    const status = enabled ? green('✔') : yellow('✘');
    const name = feature.charAt(0).toUpperCase() + feature.slice(1);
    return `${status} ${name}`;
  }).join('\n');
  
  console.log(featureStatus);
  console.log();
};

export const getFinalConfirmation = () => ({
  name: 'confirm',
  type: 'confirm',
  message: 'Create project with these features?',
  default: true
});